home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WWTCLKit / WWTTTimerIBInspector.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  7.7 KB  |  263 lines

  1. /* WWTTTimerIBInspector.m
  2.  * Written By:  Thomas Burkholder
  3.  *
  4.  * You may freely copy, distribute, and reuse the code in this example.
  5.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  6.  * fitness for any particular use.
  7.  */
  8. // hacked on by wave for WavesWorld
  9.  
  10. #import "WWTTTimerIBInspector.h"
  11.  
  12. @implementation WWTTTimer (AttributesInspector)
  13.  
  14. - (const char *)getInspectorClassName
  15. {
  16.     return "WWTTTimerIBInspector";
  17. }
  18.  
  19. - (NXImage *)getIBImage
  20. {
  21.     return [NXImage findImageNamed:"WWTTTimer"];
  22. }
  23.  
  24. @end
  25.  
  26. @implementation WWTTTimerIBInspector
  27.  
  28. static int thresholds[] = {NX_BASETHRESHOLD, 
  29.                             NX_RUNMODALTHRESHOLD, 
  30.                             NX_MODALRESPTHRESHOLD};
  31. - init
  32. {
  33.     char buf[MAXPATHLEN+1];
  34.     NXBundle *bundle;
  35.     [super init];
  36.  
  37.    preControlStringSize = 256;
  38.    preControlString = (char *)NXZoneCalloc([self zone], preControlStringSize, sizeof(char));
  39.  
  40.    conditionalSize = 256;
  41.    conditional = (char *)NXZoneCalloc([self zone], conditionalSize, sizeof(char));
  42.  
  43.    controlStringSize = 256;
  44.    controlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  45.  
  46.    postControlStringSize = 256;
  47.    postControlString = (char *)NXZoneCalloc([self zone], postControlStringSize, sizeof(char));
  48.  
  49.     bundle = [NXBundle bundleForClass:[WWTTTimer class]];
  50.     [bundle getPath:buf forResource:"WWTTTimerIBInspector" ofType:"nib"];
  51.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  52.  
  53.    // since the textView was "hidden" inside the ScrollView, we couldn't do this in IB, so...
  54.    [preControlStringText setDelegate:self];
  55.    [conditionalText setDelegate:self];
  56.    [theControlStringText setDelegate:self];
  57.    [postControlStringText setDelegate:self];
  58.  
  59.    [self revert:self];
  60.  
  61.     return self;
  62. }
  63.  
  64. - free
  65. {
  66.   if (preControlString) { NXZoneFree([self zone], preControlString); }
  67.   if (conditional) { NXZoneFree([self zone], conditional); }
  68.   if (controlString) { NXZoneFree([self zone], controlString); }
  69.   if (postControlString) { NXZoneFree([self zone], postControlString); }
  70.   return [super free];
  71. }
  72.  
  73. - ok:sender
  74. {
  75.   int   cnt;
  76.  
  77.   cnt = [preControlStringText textLength];
  78.   while (cnt >= preControlStringSize)
  79.   {  preControlStringSize *= 2;
  80.      preControlString = (char *)NXZoneRealloc([self zone], preControlString, preControlStringSize);
  81.   }
  82.   *preControlString = '\0';
  83.   [preControlStringText getSubstring:preControlString start:0 length:(cnt + 1)];
  84.   [object setPreControlString:preControlString];
  85.  
  86.   cnt = [conditionalText textLength];
  87.   while (cnt >= conditionalSize)
  88.   {  conditionalSize *= 2;
  89.      conditional = (char *)NXZoneRealloc([self zone], conditional, conditionalSize);
  90.   }
  91.   *conditional = '\0';
  92.   [conditionalText getSubstring:conditional start:0 length:(cnt + 1)];
  93.   [object setConditional:conditional];
  94.  
  95.   cnt = [theControlStringText textLength];
  96.   while (cnt >= controlStringSize)
  97.   {  controlStringSize *= 2;
  98.      controlString = (char *)NXZoneRealloc([self zone], controlString, controlStringSize);
  99.   }
  100.   *controlString = '\0';
  101.   [theControlStringText getSubstring:controlString start:0 length:(cnt + 1)];
  102.   [object setControlString:controlString];
  103.  
  104.   cnt = [postControlStringText textLength];
  105.   while (cnt >= postControlStringSize)
  106.   {  postControlStringSize *= 2;
  107.      postControlString = (char *)NXZoneRealloc([self zone], postControlString, postControlStringSize);
  108.   }
  109.   *postControlString = '\0';
  110.   [postControlStringText getSubstring:postControlString start:0 length:(cnt + 1)];
  111.   [object setPostControlString:postControlString];
  112.  
  113.     [window disableFlushWindow];
  114.     [object setAutoStart:[autoStartSwitch state]];
  115.     [object setPeriod:[periodField doubleValue]];
  116.     [object setPriority:[priorityField intValue]];
  117.     [object setVisibleDebug:[visibleDebugSwitch state]];
  118.         if ([[behaviorMatrix selectedCell] tag] == 0) // it's a wrap
  119.         {  [object setWrap:YES];
  120.            [object setFiniteLife:NO];
  121.            [object setConditionalLifespan:NO];
  122.         }
  123.         else
  124.         {  if ([[behaviorMatrix selectedCell] tag] == 1) // it's days are numbered
  125.            {  [object setWrap:NO];
  126.               [object setFiniteLife:YES];
  127.               [object setConditionalLifespan:NO];
  128.            }
  129.            else
  130.            {  if ([[behaviorMatrix selectedCell] tag] == 2) // it's days are numbered
  131.               {  [object setWrap:NO];
  132.                  [object setFiniteLife:NO];
  133.                  [object setConditionalLifespan:NO];
  134.               }
  135.               else  // it's conditional
  136.               {  [object setWrap:NO];
  137.                  [object setFiniteLife:YES];
  138.                  [object setConditionalLifespan:YES];
  139.               }
  140.            }
  141.         } 
  142.     [object setSync:[syncSwitch state]];
  143.     [object setSyncValue:[syncValueField intValue]];
  144.         
  145.     [object setStartValue:[startValueField floatValue]];
  146.     [object setWrapValue:[behaviorValueField floatValue]];
  147.     [object setIncrementBy:[incrementByField floatValue]];
  148.     [self revertInspector:sender];
  149.     [window reenableFlushWindow];
  150.     [window flushWindow];
  151.     return [super ok:sender];
  152. }
  153.  
  154. - revertInspector:sender
  155. {
  156.    [autoStartSwitch setState:[object autoStart]];
  157.    [periodField setDoubleValue:[object period]];
  158.    [priorityField setIntValue:[object priority]];
  159.    [visibleDebugSwitch setState:[object visibleDebug]];
  160.  
  161.    if ([object wrap])  // check for this first
  162.    {  [behaviorMatrix selectCellWithTag:0];
  163.       [behaviorValueField setEnabled:YES];
  164.       [behaviorText setStringValue:"wrap when value is:"];
  165.    }
  166.    else
  167.    {  if ([object finiteLife])
  168.       { if ([object conditionalLifespan])  // check for this first
  169.         {  [behaviorMatrix selectCellWithTag:3];
  170.            [behaviorValueField setEnabled:NO];
  171.            [behaviorText setStringValue:"see tcl code..."];
  172.         }
  173.         else
  174.         {  [behaviorMatrix selectCellWithTag:1];
  175.            [behaviorValueField setEnabled:YES];
  176.            [behaviorText setStringValue:"die when value is:"];
  177.         }
  178.       }
  179.       else
  180.       {  [behaviorMatrix selectCellWithTag:2];
  181.          [behaviorValueField setEnabled:NO];
  182.          [behaviorText setStringValue:""];
  183.       }
  184.    }
  185.  
  186.    [syncSwitch setState:[object sync]];
  187.    [syncValueField setIntValue:[object syncValue]];
  188.    if ([object sync])
  189.    {  [syncValueField setEnabled:YES];
  190.    }
  191.    else
  192.    {  [syncValueField setEnabled:NO];
  193.    }
  194.  
  195.    [startValueField setFloatValue:[object startValue]];
  196.    [behaviorValueField setFloatValue:[object wrapValue]];
  197.    [incrementByField setFloatValue:[object incrementBy]];
  198.    [preControlStringText setText:[object preControlString]];
  199.    [conditionalText setText:[object conditional]];
  200.    [theControlStringText setText:[object controlString]];
  201.    [postControlStringText setText:[object postControlString]];
  202.  
  203.    return self;
  204. }
  205.  
  206. - revert:sender
  207. {
  208.    [window disableFlushWindow];
  209.    [self revertInspector:sender];
  210.    [window reenableFlushWindow];
  211.    [window flushWindow];
  212.    return [super revert:sender];
  213. }
  214.  
  215. - setBehavior:sender
  216. {
  217.    if ([[sender selectedCell] tag] == 0) // it's a wrap
  218.    {  [object setWrap:YES];
  219.       [object setFiniteLife:NO];
  220.    }
  221.    else
  222.    {  if ([[behaviorMatrix selectedCell] tag] == 1) // it's days are numbered
  223.       {  [object setWrap:NO];
  224.          [object setFiniteLife:YES];
  225.       }
  226.       else
  227.       {  if ([[behaviorMatrix selectedCell] tag] == 2) // it's days are numbered
  228.          {  [object setWrap:NO];
  229.             [object setFiniteLife:NO];
  230.             [object setConditionalLifespan:NO];
  231.          }
  232.          else  // it's conditional
  233.          {  [object setWrap:NO];
  234.             [object setFiniteLife:YES];
  235.             [object setConditionalLifespan:YES];
  236.          }
  237.       }
  238.    } 
  239.    return [self ok:self];
  240. }
  241.  
  242. - thresholdPopped:sender
  243. {
  244.    int val;
  245.  
  246.  
  247.    val = [[sender selectedCell] tag];
  248.    if (val < 0)
  249.    {  return self;
  250.    }
  251.    [priorityField setIntValue:thresholds[val]];
  252.    return [self ok:self];
  253. }
  254.  
  255. //
  256. - (BOOL)wantsButtons    { return YES; }
  257.  
  258. // text delegate methods
  259. - textDidChange:sender {  return [self touch:sender]; }
  260.  
  261.  
  262. @end
  263.